package com.legstar.talend;

import java.io.File;
import java.io.FileNotFoundException;

import com.legstar.talend.io.ZosFileInputStream;
import com.legstar.talend.io.ZosFixedFileInputStream;
import com.legstar.talend.io.ZosVariableFileInputStream;
import com.legstar.talend.io.ZosVariableRDWFileInputStream;

/**
 * A utility class to determine the type of file i/o needed based upon the user
 * options selected in PDI.
 * 
 */
public class ZosFileInputStreamFactory {

    /**
     * A utility class.
     */
    private ZosFileInputStreamFactory() {

    }

    /**
     * The z/OS file can be fixed length or variable length. Furthermore,
     * variable length files can have RDW prefixes or not.
     * 
     * @param file the underlying z/OS file
     * @param isVariableLength if the file records are variable length
     * @param hasRecordDescriptorWord if the file records start with a RDW
     * @return a stream reader appropriate for the type of z/OS records in the
     *         file
     * @throws FileNotFoundException if underlying file not found
     */
    public static ZosFileInputStream create(final File file,
            final boolean isVariableLength,
            final boolean hasRecordDescriptorWord) throws FileNotFoundException {

        if (isVariableLength) {
            if (hasRecordDescriptorWord) {
                return new ZosVariableRDWFileInputStream(file);
            } else {
                return new ZosVariableFileInputStream(file);
            }
        } else {
            return new ZosFixedFileInputStream(file);
        }
    }

}
